/**
 * created by zhouli on 2019/1/9
 */
import config from 'config';
import httpFetch from 'share/httpFetch';
import errorMessage from 'share/errorMessage';
export default {
  //查询授权策略下面的人员
  //只有当策略类型是 user 的时候，适用人员才可以使用
  //其他类型
  getPolicyDetailPersons(params) {
    // let params = {
    //   policyId,
    //   keyword,
    //   page,
    //   size
    // }
    return new Promise(function (resolve, reject) {
      httpFetch.get(config.baseUrl + '/api/authorization/policy/detail/page' ,params)
        .then(function (res) {
          resolve(res)
        })
        .catch(function (err) {
          errorMessage(err);
          reject(err);
        })
    })
  },
  //删除授权策略的人
  deletePolicyDetailPerson(params) {
    // let params = {
    //   detailId
    // }
    return new Promise(function (resolve, reject) {
      httpFetch.delete(config.baseUrl + '/api/authorization/policy/detail',params)
        .then(function (res) {
          resolve(res)
        })
        .catch(function (err) {
          errorMessage(err.response);
          reject(err.response);
        })
    })
  },
  //添加授权策略的人(有了批量添加接口，这个可不用)
  addPolicyDetailPerson(params) {
    // let params = {
    //   "tenantId":"985801821654523905",
    //   "policyId":"1",
    //   "grantType":"授权策略类型（all,deptmgr,user）",
    //   "grantValue":123,//id
    //   "enabled":true
    // }
    return new Promise(function (resolve, reject) {
      httpFetch.post(config.baseUrl + '/api/authorization/policy/detail',params)
        .then(function (res) {
          resolve(res)
        })
        .catch(function (err) {
          errorMessage(err.response);
          reject(err.response);
        })
    })
  },
  //添加授权策略的人(批量)
  addPolicyDetailPersonBatch(params) {
    // let params = {
    //   "policyId":"1",
    //   "body":["1","2"]
    // }
    return new Promise(function (resolve, reject) {
      httpFetch.post(config.baseUrl + '/api/authorization/policy/detail/batch?policyId='+params.policyId,params.body)
        .then(function (res) {
          resolve(res)
        })
        .catch(function (err) {
          errorMessage(err.response);
          reject(err.response);
        })
    })
  },
}
